<template>
	<view>
		<uv-modal ref="modalRef" title="异常提示" :content='content' @confirm="confirm"></uv-modal>
	</view>
</template>

<script setup>
	import {
		ref,
	} from "vue";

	import {
		gotoAppPermissionSetting,
		requestAndroidPermission,
		judgeIosPermission
	} from "@/js_sdk/wa-permission/permission.js"

	const props = defineProps({
		content: String,
	})

	const modalRef = ref()

	function checkPermission(str) {
		// #ifdef APP-PLUS
		const isIos = plus.os.name === "iOS"
		let type = ""

		switch (str) {
			case "相册":
				type = isIos ? 'photoLibrary' : 'android.permission.READ_EXTERNAL_STORAGE'
				break;
		}

		if (isIos) {
			if (judgeIosPermission(type)) {
				// modalRef.value.open()
			}
		} else {
			requestAndroidPermission(type).then(result => {
				if (result !== 1) {
					modalRef.value.open()
				}
			})
		}
		// #endif
	}

	function confirm() {
		modalRef.value.close()
		// #ifdef APP-PLUS
		gotoAppPermissionSetting()
		// #endif

		// #ifdef MP-WEIXIN
		uni.openSetting()
		// #endif
	}


	defineExpose({
		checkPermission,
	});
</script>

<style>
</style>